package com.leoman.dao;

import com.leoman.entity.Attention;
import com.leoman.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * AttentionDao
 * Created by 涂奕恒 on 2016/11/23 0023 下午 3:41.
 */
public interface AttentionDao extends JpaRepository<Attention, Integer>, JpaSpecificationExecutor<Attention> {

    @Query("select a from Attention a where a.fromUser.id = ?1 and a.toUser.id = ?2")
    Attention findOneByParams(Integer fromUserId, Integer toUserId);

    @Query("select a from User a where a.id <> ?1 and a.id not in (select b.toUser.id from Attention b where b.fromUser.id = ?1) and a.id not in (select c.fromUser.id from Attention c where c.toUser.id = ?1)")
    List<User> findThreeUserInfoVo(Integer userId);

    @Query("select a from Attention a where a.fromUser.id = ?1")
    List<User> findAttentionList(Integer userId);

    @Query("select a from Attention a where a.toUser.id = ?1")
    List<User> findFansList(Integer userId);

    @Query("select a from Attention a where a.fromUser.id = ?1 and a.isRead = 0")
    List<User> findAttentionListNoRead(Integer userId);

    @Query("select a from Attention a where a.toUser.id = ?1 and a.isRead = 0")
    List<User> findFansListNoRead(Integer userId);
}